<template>
  <div>
    <basic-container>
      <avue-tabs :option="option"
                 v-model="form"
                 @change="handleChange"
                 @submit="handleSubmit"></avue-tabs>
    </basic-container>
  </div>
</template>

<script>
  import option from "@/const/user/info";
  import {userInfo,submit} from "@/api/system/user";
  export default {
    data() {
      return {
        type: "info",
        option: option,
        form: {}
      };
    },
    created() {
      this.handleWitch();
    },
    methods: {
      handleSubmit() {
        submit(this.form).then(()=>{
            let ui1=(this.$store.getters.userInfo)
            ui1.userName = this.form.realName;
           this.$store.dispatch("SET_USERIFNO",ui1);
        this.$message({
          message:"修改成功",
          type: "success"
        })
        })
      },
      handleWitch() {
        let u =null;
        userInfo().then((res)=>{
           u = res.data.data;
        if (this.type === "info") {
          this.form = {
            realName: u.name,
            phone: u.phone
          };
        } else if (this.type === "password") {
          this.form = {
            oldpassword: "",
            newpassword: "",
            newpasswords: ""
          };
        }

      })


      },
      handleChange(item) {
        this.type = item.prop;
        this.handleWitch();
      }
    }
  };
</script>

<style>
</style>
